﻿Imports System.Xml.Serialization
Imports System.Text.RegularExpressions

Public Class AppConfig
    Inherits DefaultConfig

    Private Shared mConfigInfo As AppConfigInfo

    Private Shared mConfigFilePath As String
    Private Shared mFileDateTime As DateTime


    Public Shared ReadOnly Property ConfigInfo() As AppConfigInfo
        Get
            Return mConfigInfo
        End Get
    End Property

    Shared Sub New()
        mConfigInfo = load()
    End Sub

    Public Shared Function load() As AppConfigInfo
        If IO.File.Exists(ConfigFilePath) Then
            Try
                If mConfigInfo Is Nothing Then
                    mConfigInfo = New AppConfigInfo
                End If
                Return CType(LoadConfig(mFileDateTime, ConfigFilePath, mConfigInfo), AppConfigInfo)
            Catch ex As Exception
                mConfigInfo = New AppConfigInfo
                REM Throw ex
            End Try
        End If
        Return New AppConfigInfo
    End Function



    REM 配置文件路径
    Public Overloads Shared ReadOnly Property ConfigFilePath() As String
        Get
            If String.IsNullOrEmpty(mConfigFilePath) Then
                Dim Path As String = AppSettings("ConfigPath")
                If String.IsNullOrEmpty(Path) Then Path = "/config/"
                If Not Path.EndsWith("/") Then Path = String.Concat(Path, "/")
                Path = System.Web.HttpContext.Current.Server.MapPath(String.Format("{0}app.config", Path))
                If IO.File.Exists(Path) Then
                    mConfigFilePath = Path
                Else
                    Path = Nothing
                End If
            End If
            Return mConfigFilePath
        End Get
    End Property

    Protected Overrides Sub Finalize()
        mConfigInfo = Nothing
        MyBase.Finalize()
    End Sub


End Class

''' <summary>
''' 站点配置信息
''' </summary>
''' <remarks></remarks>
<Serializable()> <XmlRoot("Application")> Public Class AppConfigInfo
    Implements IConfigInfo

    ''' <summary>
    ''' 是否启用用户单点登录
    ''' </summary>
    ''' <remarks></remarks>
    Public PassportSSO As Boolean = False

    ''' <summary>
    ''' 用户登录页面
    ''' </summary>
    ''' <remarks></remarks>
    Public PassportLoginPage As String

    ''' <summary>
    ''' 用户主站凭证获取页面
    ''' </summary>
    ''' <remarks></remarks>
    Public PassportGetTokenPage As String

    ''' <summary>
    ''' 用户主站站点Cookie名称
    ''' </summary>
    ''' <remarks></remarks>
    Public PassportTokenCookie As String


    ''' <summary>
    ''' 是否启用管理员单点登录
    ''' </summary>
    ''' <remarks></remarks>
    Public AdminSSO As Boolean = False

    ''' <summary>
    ''' 管理员登录页面
    ''' </summary>
    ''' <remarks></remarks>
    Public AdminLoginPage As String

    ''' <summary>
    ''' 管理员登录是否要检查验证码
    ''' </summary>
    ''' <remarks>默认为false</remarks>
    Public AdminCheckVaidCode As Boolean = False

    ''' <summary>
    ''' 管理员凭证获取页面
    ''' </summary>
    ''' <remarks></remarks>
    Public AdminGetTokenPage As String

    ''' <summary>
    ''' Html静态文件目录
    ''' </summary>
    ''' <remarks></remarks>
    Public HtmlPath As String               '

    Public LabelPath As String              'label.xml文件默认目录
    Public TablesUrl As String              'Table文件路径
    Public SqlLabel As String               '过滤用的Sql标识
    Public Filter As String                 '过滤用的字符串标识
    Public KWIntercept As String = ""       '拦截关键字列表
    Public KWInterceptMethod As Integer = 0 '拦截关键字模式(0不使用，1 get, 2 post)
    Public KWRecord As String               '记录关键字列表
    Public KWRecordMethod As Integer = 0    '记录关键字模式(0不使用，1 get, 2 post)
    Public Domain As String = ""            '网站根域名,加进Cookie

    Public PassportCookie As String         '通行证的Cookie名称

    ''' <summary>
    ''' 缓存文件扩展名
    ''' </summary>
    ''' <remarks></remarks>
    Public CacheFileExtName As String

    ''' <summary>
    ''' xslt文件缓存时间
    ''' </summary>
    ''' <remarks></remarks>
    Public XsltCacheTime As Integer = 120

    ''' <summary>
    ''' 缓存文件基础目录
    ''' </summary>
    ''' <remarks></remarks>
    Public CachePath As String

    ''' <summary>
    ''' 全局是否启用压缩，默认为是,页面上的配置优先于全局
    ''' </summary>
    ''' <remarks></remarks>
    Public Compression As String = "true"  '

    ''' <summary>
    ''' 上传文件基本目录
    ''' </summary>
    ''' <remarks></remarks>
    Public UploadBasePath As String

    ''' <summary>
    ''' 上传文件相对目录
    ''' </summary>
    ''' <remarks></remarks>
    Public UploadPath As String

    ''' <summary>
    ''' 缩略图生成目录
    ''' </summary>
    ''' <remarks></remarks>
    Public ThumbnailPath As String

    ''' <summary>
    ''' 缩略模式
    ''' </summary>
    ''' <remarks>101,102,200</remarks>
    Public ThumbnailMode As Integer = 101

    ''' <summary>
    ''' 缩略图宽度,单位:像素
    ''' </summary>
    ''' <remarks>像素单位</remarks>
    Public ThumbnailWidth As Integer = 200

    ''' <summary>
    ''' 缩略图高度,单位:像素
    ''' </summary>
    ''' <remarks>像素单位</remarks>
    Public ThumbnailHeight As Integer = 200

    ''' <summary>
    ''' 允许上传文件类型
    ''' </summary>
    ''' <remarks></remarks>
    Public AllowUploadTypes As String

    ''' <summary>
    ''' 上传图片类型,用于控制生成缩略图和水印
    ''' </summary>
    ''' <remarks></remarks>
    Public ImgTypes As String

    ''' <summary>
    ''' 最大上传文件大小,默认200,单位：K
    ''' </summary>
    ''' <remarks></remarks>
    Public MaxUploadSize As Integer = 200

    ''' <summary>
    ''' 水印类型 0不加用 1文字 2图片(默认)
    ''' </summary>
    ''' <remarks></remarks>
    Public Watermarktype As Integer = 0

    Public Watermarkalpha As Single = 0.2F

    ''' <summary>
    ''' 水印文字，可用{0}日期 {1}用户名 
    ''' </summary>
    ''' <remarks></remarks>
    Public Watermarktext As String = ""

    ''' <summary>
    ''' 水印图片路径
    ''' </summary>
    ''' <remarks></remarks>
    Public Watermarkpic As String

    ''' <summary>
    ''' 水印文字字体
    ''' </summary>
    ''' <remarks></remarks>
    Public Watermarkfontname As String

    ''' <summary>
    ''' 水印文字大小(单位像素)
    ''' </summary>
    ''' <remarks></remarks>
    Public Watermarkfontsize As Integer

    ''' <summary>
    ''' 打开调试功能
    ''' </summary>
    ''' <remarks></remarks>
    Public Debug As Boolean = False
End Class




